define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'qingdongwms/notice/aftermarket/index' + location.search,
                    add_url: 'qingdongwms/notice/aftermarket/add',
                    edit_url: 'qingdongwms/notice/aftermarket/edit',
                    del_url: 'qingdongwms/notice/aftermarket/del',
                    table: 'aftermarket'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                columns: [
                    [
                        {field: 'state', checkbox: true},
                        {field: 'title', title: __('标题'),operate: 'LIKE'},
                        {
                            field: 'type_ids',
                            title: '信息库类型  [请通过侧边分类筛选]',
                            operate: 'LIKE',
                            visible: false,
                            placeholder: '',
                            addclass:'hidden'
                        },
                        {field: 'method', title: __('处理方式'),operate: false},
                        {field: 'click_number', title: __('点击次数'),operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {
                            field     : 'operate',
                            title     : __('Operate'),
                            table     : table,
                            events    : Table.api.events.operate,
                            formatter : Table.api.formatter.operate,
                            buttons   : [
                                {
                                    name: 'edit',
                                    text: __('编辑'),
                                    title: __('编辑'),
                                    classname: 'records btn-dialog',
                                    url: 'qingdongwms/notice/aftermarket/edit',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'del',
                                    text: __('删除'),
                                    title: __('删除'),
                                    classname: 'records btn-ajax',
                                    url: 'qingdongwms/notice/aftermarket/del',
                                    confirm: '确定要删除吗?',
                                    refresh:true,
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ]
                        }
                    ]
                ],
                //启用普通表单搜索
                commonSearch: true,
                searchFormVisible: true,
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            // 为表格绑定事件
            require(['jstree'], function () {
                //全选和展开
                $('#jsTree').on("changed.jstree", function (e, data) {
                    var type_ids = data.selected;
                    $(".commonsearch-table input[name=type_ids]").val(','+type_ids.toString()+',');
                    table.bootstrapTable('refresh', {});
                    return false;
                });
                $('#jsTree').jstree({
                    "types": {
                        "list": {
                            "icon": "fa fa-list"
                        }
                    },
                    'plugins': ["types"],
                    "core": {
                        'check_callback': true,
                        "data": Config.typeList
                    }
                });
            });



            $('.search').hide();
            $('.btn-import').hide();

        },
        add: function () {
            Controller.api.bindevent();
        },

        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                thumb: function (value, row, index) {
                    var style = row.storage == 'upyun' ? '!/fwfh/120x90' : '';
                    return '<img src="' + row.image + '" data-tips-image alt="" title="封面图" style="max-height:90px;max-width:120px">';

                },

            },

        }

    };
    return Controller;
});